package com.mmsj;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * @author ChuXuan
 */
public class MenuAdapter extends BaseAdapter {

    private Context context;

    private List<Menu> menuList;

    public MenuAdapter(Context context, List<Menu> menuList) {
        this.context = context;
        this.menuList = menuList;
    }
    public MenuAdapter() {
    }
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
           convertView = LayoutInflater.from(context).inflate(R.layout.menu_list_item, null);
        }
        // 获取控键
        TextView name = convertView.findViewById(R.id.tv_name);
        TextView description = convertView.findViewById(R.id.tv_desc);
        TextView price = convertView.findViewById(R.id.tv_price);
        // 设置数据
        name.setText(menuList.get(position).getName());
        description.setText(menuList.get(position).getDescription());
        price.setText(menuList.get(position).getPrice().toString());
        return convertView;
    }

    @Override
    public int getCount() {
        return menuList.size();
    }

    @Override
    public Object getItem(int position) {
        return menuList.get(position);
    }
}
